const fs = require("fs");
const path = require("path");
var stdin = process.stdin;
var index = 0;
var infor =[];
console.log("请输入要创建的文件夹：");

stdin.on("data", function(chunk){
    var str = chunk.toString("utf-8").slice(0,-2); //去掉回车键slice(0,-2)
    infor[index] = str;
    if(index == 0){
        if(infor[0]=="mkdir filedir"){
            fs.mkdir(path.join(__dirname,'/filedir'),(err)=>{
                if(err){console.log(err)}
                else{
                    console.log("文件目录创建成功！！");
                    console.log("请输入要创建的文件夹");
                }  
            })
            index++;
        }
    }
    else if(index ==1){
        if(infor[1]=="touch file1.txt"){
            var filePath = path.join(__dirname,"/filedir/file1.txt");
            var writeable = fs.createWriteStream(filePath);
            writeable.write("hello node");
            writeable.end();
            console.log("文件创建成功");
            console.log("请输入要删除的文件：")
            index++;
        }
    }
    else if(index ==2){
        if(infor[2]=="delect file1.txt"){
            fs.unlinkSync(path.join(__dirname, '/filedir/file1.txt'));
        }
        process.exit();
    }
    
})